//  This product includes software developed by Denim Group, Ltd. (http://www.denimgroup.com/)
// All use and distribution of the Denim Group developed software is subject to Version 2.0
// of the Apache License (http://www.apache.org/licenses/LICENSE-2.0).

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml.Serialization;

namespace AppScan.DefectLogger
{
	public class DefectSystemConfig
	{
		#region Members
		private string _serverUrl = string.Empty;
        private string _userName = string.Empty;
        private string _password = string.Empty;
        private string _domainName = string.Empty;
        private string _projectName = string.Empty;
		private List<Field> _fields = new List<Field>();
		#endregion

		#region Properties
		public string ServerUrl
		{
			get { return _serverUrl; }
			set { _serverUrl = value; }
		}
		public string UserName
		{
			get { return _userName; }
			set { _userName = value; }
		}
		[XmlIgnore]
		public string Password
		{
			get { return _password; }
			set { _password = value; }
		}
		public string DomainName
		{
			get { return _domainName; }
			set { _domainName = value; }
		}
		public string ProjectName
		{
			get { return _projectName; }
			set { _projectName = value; }
		}
		public List<Field> Fields

		{
			get { return _fields; }
			set { _fields = value; }
		}
		#endregion

		public string ToXml()
		{
			XmlSerializer serializer = new XmlSerializer(typeof(DefectSystemConfig));
			StringBuilder sb = new StringBuilder();
			StringWriter sw = new StringWriter(sb);
			serializer.Serialize(sw, this);

			return sb.ToString();
		}

		public static DefectSystemConfig FromXml(string xml)
		{
			try
			{
				XmlSerializer serializer = new XmlSerializer(typeof(DefectSystemConfig));
				StringReader sr = new StringReader(xml);
				return serializer.Deserialize(sr) as DefectSystemConfig;
			}
			catch (Exception)
			{
				return null;
			}
		}
	}
}
